﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace CHAPServer
{
    internal class Util
    {
        public static string Hash(string data)
        {
            //  Encrypt Key
            byte[] tmpBytes = ASCIIEncoding.ASCII.GetBytes(data);
            byte[] bHashKey = new MD5CryptoServiceProvider().ComputeHash(tmpBytes);
            string HashKey = ByteArrayToString(bHashKey);

            return HashKey;
        }

        public static string ByteArrayToString(byte[] arrInput)
        {
            int i;
            StringBuilder sOutput = new StringBuilder(arrInput.Length);
            for (i = 0; i < arrInput.Length - 1; i++)
            {
                sOutput.Append(arrInput[i].ToString("X2"));
            }
            return sOutput.ToString();
        }
    }
}